package result;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;

import org.apache.struts2.ServletActionContext;

public class DownloadAction {
	private InputStream mystream;//字节输出
	private int id;
	private String fileName;;
	//另存为窗口的文件名为ISO－8859－1编码
	public String getFileName() {
		try {
			byte[] b = fileName.getBytes("utf-8");
			fileName=new String(b,"ISO-8859-1");
			return fileName;
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
			return fileName;
		}
	}
	
	public String execute(){
		//检查是否有权限，没权限return nologin
		//有权限，扣除积分
		//积分不够 return ???
		try {
			//fileName=id+".jpg";
			fileName="oo惹火.jpg";
			String path=ServletActionContext.getServletContext().getRealPath("/images");
			mystream=new FileInputStream(new File(path+"/"+fileName));
			return "success";
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			return null;
		}
	}

	public InputStream getMystream() {
		return mystream;
	}

	public void setMystream(InputStream mystream) {
		this.mystream = mystream;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}
}
